package com.zbkj.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zbkj.admin.model.req.MerchantInfoReq;
import com.zbkj.admin.model.vo.MerchantInfoVo;
import com.zbkj.admin.service.MerchantV2Service;
import com.zbkj.dal.common.exception.CrmebException;
import com.zbkj.dal.dao.MerchantDao;
import com.zbkj.dal.entity.merchant.Merchant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Slf4j
@Service
public class MerchantV2ServiceImpl implements MerchantV2Service {

    @Resource
    private MerchantDao merchantDao;

    @Override
    public MerchantInfoVo merchantInfo(MerchantInfoReq req) {
        LambdaQueryWrapper<Merchant> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Merchant::getName, req.getName());
        Merchant merchant = merchantDao.selectOne(wrapper);
        if (Objects.isNull(merchant)) {
            throw new CrmebException("商户信息不存在");
        }
        MerchantInfoVo merchantInfoVo = new MerchantInfoVo();
        merchantInfoVo.setMerchantId(merchant.getId());
        merchantInfoVo.setMerchantName(merchant.getName());
        return merchantInfoVo;
    }
}
